package impl;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;

import java.util.Comparator;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Keevu
 * Date: 17/08/11
 * Time: 15:30
 * To change this template use File | Settings | File Templates.
 */
public class BubbleSorter extends AbstractSorter {

    public BubbleSorter() {
        super(SorterType.BUBBLE);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        int w = ts.size();
        for (int i = 0; i < w; i++) {
            for (int g = i + 1; g < w; g++) {
                if (greater(tComparator, ts, i, g)) {
                    swap(ts,i,g);
                }
            }
        }
    }
}
